require('../models/merchant.model');
const mongoose = require('mongoose');
const merchantModel = mongoose.model('merchants');
module.exports = {
    addMerchant:addMerchant,
    findMerchantStatusById:findMerchantStatusById,
    findMerchantByName:findMerchantByName,
    replaceMerchant:replaceMerchant
}

function addMerchant(merchant,callback){
    merchantModel.create(merchant,function (error,doc) {
        callback(error,doc);
    });
}

function findMerchantStatusById(merchantId,callback){
    merchantModel.findOne({_id:merchantId},"mStatus",function (error,docs) {
        callback(error,docs);
    });
}

function findMerchantByName(name,callback){
    merchantModel.findOne({name:name},function (error,docs) {
        callback(error,docs);
    });
}

function replaceMerchant(merchant,callback){
    merchantModel.replaceOne({name:merchant.name},merchant,function (error,doc) {
        callback(error,doc);
    })
}